//
//  PAPayAlertView.m
//  PAMobileWallet
//
//  Created by shen pu on 13-7-12.
//  Copyright (c) 2013年 平安付. All rights reserved.
//

#import "PAPayAlertView.h"
#import "UIColor+Extend.h"
#import "PAAsynImageView.h"
#import <QuartzCore/QuartzCore.h>

@implementation PAPayAlertView
@synthesize phoneNameLable;
@synthesize payMoneyLable;
@synthesize PA_delegate;
@synthesize alerView;

@synthesize unRegisterAlert;
@synthesize photoImageView;
@synthesize warningLAB;
@synthesize targetRealNameTF;

@synthesize payLable;
@synthesize yuanLable;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        self.frame = CGRectMake(0, 0, 320, iPhone5?548:460);
        self.backgroundColor = [UIColor darkTextColor];
        self.alpha = 0.7;
        
        CGSize viewHeight = CGSizeMake(584/2, 424/2);
        
        alerView = [[UIView alloc] initWithFrame:CGRectMake((320-viewHeight.width)/2, iPhone5?(548-216-viewHeight.height-20):(460-216-viewHeight.height-20), viewHeight.width, viewHeight.height)];
        
        UIImageView * payAlertImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, viewHeight.width, viewHeight.height)];
        payAlertImage.image = [UIImage imageNamed:@"pay_tool.png"];
        [alerView addSubview:payAlertImage];
        
        CGRect rect = alerView.frame;
        rect.origin.y += 30;
        self.unRegisterAlert = [[UIView alloc] initWithFrame:rect];
        
        UIImageView *cycleIV = [[UIImageView alloc] initWithFrame:CGRectMake((578/2-86/2-100-10)/2-4, 15-3, 86/2+8, 86/2+8)];
        cycleIV.image = [UIImage imageNamed:@"contact_face_non.png"];
        [alerView addSubview:cycleIV];
        
        self.photoImageView = [[PAAsynImageView alloc] initWithFrame:CGRectMake((578/2-86/2-100-10)/2, 15, 86/2, 86/2)];
        self.photoImageView.cornerRadius = self.photoImageView.frame.size.height/2;
        self.photoImageView.backgroundColor = [UIColor clearColor];
        [alerView addSubview:self.photoImageView];

        phoneNameLable = [[UILabel alloc] initWithFrame:CGRectMake((578/2-86/2-100-10)/2 + 86/2 + 10,15+(86/2-30)/2, 160, 30)];
        phoneNameLable.textColor = ENABLE_COLOR;
        phoneNameLable.text = @"张三";
        phoneNameLable.font = [UIFont systemFontOfSize:18.0];
        phoneNameLable.textAlignment = NSTextAlignmentLeft;
        phoneNameLable.backgroundColor = [UIColor clearColor];
        [alerView addSubview:phoneNameLable];

        payLable = [[UILabel alloc] initWithFrame:CGRectMake((578/2-160)/2,3+86/2+40,80/2, 40)];
        payLable.textColor = ENABLE_COLOR;
        payLable.text = @"支付";
        payLable.textAlignment = NSTextAlignmentLeft;
        payLable.backgroundColor = [UIColor clearColor];
        payLable.font = [UIFont systemFontOfSize:18.0];
        [alerView addSubview:payLable];

        payMoneyLable = [[UILabel alloc] initWithFrame:CGRectMake((578/2-160)/2+40,3+86/2+40,200/2, 40)];
        payMoneyLable.textColor = [UIColor colorWithHexString:@"#f77332"];
        payMoneyLable.text = @"320";
        payMoneyLable.font = [UIFont systemFontOfSize:20.0];
        payMoneyLable.textAlignment = NSTextAlignmentCenter;
        payMoneyLable.backgroundColor = [UIColor clearColor];
        [alerView addSubview:payMoneyLable];
        
        yuanLable = [[UILabel alloc] initWithFrame:CGRectMake((578/2-160)/2+40+100,3+86/2+40,40/2, 40)];
        yuanLable.textColor = ENABLE_COLOR;
        yuanLable.text = @"元";
        yuanLable.textAlignment = NSTextAlignmentRight;
        yuanLable.backgroundColor = [UIColor clearColor];
        yuanLable.font = [UIFont systemFontOfSize:18.0];
        [alerView addSubview:yuanLable];

        for (int i = 0; i < 2; i++){
            UIButton * alerButton = [UIButton buttonWithType:UIButtonTypeCustom];
            alerButton.backgroundColor = [UIColor clearColor];
            if (i == 0)
            {
                [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_A1.png"] forState:UIControlStateNormal];
                [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_A2.png"] forState:UIControlStateHighlighted];
                [alerButton setTitle:@"确定" forState:UIControlStateNormal];
                [alerButton setTitleColor:ABLE_COLOR forState:UIControlStateNormal];
                [alerButton setTitleColor:ABLE_COLOR forState:UIControlStateHighlighted];
                alerButton.frame = CGRectMake((584/2-258 + 20)/2-13,8+86/2+50+30,258/2,82/2);
            }
            else
            {
                [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_B1.png"] forState:UIControlStateNormal];
                [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_B2.png"] forState:UIControlStateHighlighted];
                [alerButton setTitle:@"取消" forState:UIControlStateNormal];
                [alerButton setTitleColor:ENABLE_COLOR forState:UIControlStateNormal];
                [alerButton setTitleColor:ENABLE_COLOR forState:UIControlStateHighlighted];
                alerButton.frame = CGRectMake((584/2-258 + 20)/2+258/2+10-13,8+86/2+50+30,258/2,82/2);
            }
            [alerButton addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
            //alerButton.titleLabel.textColor = [UIColor colorWithHexString:@"#ACB086"];
            //alerButton.tintColor = [UIColor colorWithHexString:@"#ACB086"];
            [alerView addSubview:alerButton];
        }
        //画为注册弹窗
        {
            CGSize viewHeight = CGSizeMake(584/2, 424/2);
            UIImageView * unRegisterBgIV = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, viewHeight.width, viewHeight.height)];
            unRegisterBgIV.image = [UIImage imageNamed:@"pay_tool.png"];
            [self.unRegisterAlert addSubview:unRegisterBgIV];
            
            self.warningLAB = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 254, 20)];
            [self.warningLAB setTextAlignment:NSTextAlignmentCenter];
            self.warningLAB.backgroundColor = [UIColor clearColor];
            [self.unRegisterAlert addSubview:self.warningLAB];
            
            self.targetRealNameTF = [[UITextField alloc] initWithFrame:CGRectMake(35, 85, 214, 36)];
            self.targetRealNameTF.backgroundColor = [UIColor clearColor];
            self.targetRealNameTF.placeholder = @"请输入真实姓名";
            [self.targetRealNameTF setBackground:[UIImage imageNamed:@"textbox.png"]];
            self.targetRealNameTF.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            self.targetRealNameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            self.targetRealNameTF.textAlignment = NSTextAlignmentCenter;
            self.targetRealNameTF.delegate = self;
            [self.unRegisterAlert addSubview:self.targetRealNameTF];
            [self.targetRealNameTF addTarget:self action:@selector(checktargetRealNameTF:) forControlEvents:UIControlEventEditingChanged];
            
            for (int i = 0; i < 2; i++)
            {
                UIButton * alerButton = [UIButton buttonWithType:UIButtonTypeCustom];
                alerButton.backgroundColor = [UIColor clearColor];
                if (i == 0){
                    [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_A1.png"] forState:UIControlStateNormal];
                    [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_A2.png"] forState:UIControlStateHighlighted];
                    [alerButton setTitle:@"确定" forState:UIControlStateNormal];
                    [alerButton setTitleColor:ABLE_COLOR forState:UIControlStateNormal];
                    [alerButton setTitleColor:ABLE_COLOR forState:UIControlStateHighlighted];
                    alerButton.frame = CGRectMake((584/2-258 + 20)/2-13,8+86/2+50+30,258/2,82/2);
                }
                else{
                    [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_B1.png"] forState:UIControlStateNormal];
                    [alerButton setBackgroundImage:[UIImage imageNamed:@"small_button_B2.png"] forState:UIControlStateHighlighted];
                    [alerButton setTitle:@"取消" forState:UIControlStateNormal];
                    [alerButton setTitleColor:ENABLE_COLOR forState:UIControlStateNormal];
                    [alerButton setTitleColor:ENABLE_COLOR forState:UIControlStateHighlighted];
                    alerButton.frame = CGRectMake((584/2-258 + 20)/2+258/2+10-13,8+86/2+50+30,258/2,82/2);
                }
                [alerButton addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
                //alerButton.titleLabel.textColor = [UIColor colorWithHexString:@"#ACB086"];
                //alerButton.tintColor = [UIColor colorWithHexString:@"#ACB086"];
                [self.unRegisterAlert addSubview:alerButton];
            }
        }
    }
    
    return self;
}

- (void)changeState:(UIButton *)sender
{
    if (PA_delegate)
    {
        [PA_delegate sendSelf:self sendAlertView:alerView sendButton:sender];
    }
    [self.targetRealNameTF resignFirstResponder];
}

- (void)loadUnRegisterWithAmount:(NSString *)amount phoneNum:(NSString *)phoneNum
{
    self.warningLAB.text = [NSString stringWithFormat:@"你给 %@  转账 %@元",phoneNum,amount];
}

- (void)checktargetRealNameTF:(id)sender
{
    if ([self.targetRealNameTF.text length ]>0) {
        [self.targetRealNameTF setBackground:[UIImage imageNamed:@"textbox2.png"]];
    }else{
        [self.targetRealNameTF setBackground:[UIImage imageNamed:@"textbox.png"]];
    }
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{

}
//完成 编辑 待支付对象的 电话号码
- (void)targetPhoneEndEdit:(UITextField *)targetPhoneTF
{

}
@end
